# -*- coding: utf-8 -*- 
# @project : 《Atcoder》
# @Author : created by bensonrachel on 2021/6/25
# @File : C - Bowls and Dishes.py

N, M = map(int, input().split())#DFS+判断
char1 = []
for _ in range(M):
    A, B = map(int, input().split())
    a = (A, B)
    char1.append(a)
K = int(input())
char2 = []
for _ in range(K):
    C, D = map(int, input().split())
    a = (C, D)
    char2.append(a)
tag = []
max_ = -1
def re(tag):
    cnt = 0
    for i in char1:
        if(i[0] in tag and i[1] in tag):
            cnt += 1
    return cnt
def dfs(k):
    global max_
    if(k==K):
        #print(tag)
        cnt = re(tag)
        if(cnt > max_): max_=cnt
        return
    tag.append(char2[k][0])
    dfs(k+1)
    x = tag.pop()
    tag.append(char2[k][1])
    dfs(k+1)
    x = tag.pop()
dfs(0)
print(max_)
"""
别人的做法：
product 用于求多个可迭代对象的笛卡尔积(Cartesian Product)，它跟嵌套的 for 循环等价
itertools.product(*iterables, repeat=1)
choice假设为一个包含多个元组的列表
用itertools.product(*choice)，*的意思是解包，等于用itertools.product(tuple1,tuple2,tuple3,....,)
返回也是可迭代对象，笛卡尔积
"""